import 'package:flutter/material.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/config/hc_default_theme_config.dart';
import 'package:hc_ui/theme/hc_base_theme.dart';

import 'hc_common_theme.dart';

class HcAvatarTheme extends HcBaseTheme<HcAvatarTheme> {
  double? _size;
  double? _radius;
  Color? _textColor;
  int? _changeDuration;
  TextStyle? _textStyle;
  Color? _borderColor;
  Color? _backgroundColor;

  double? _borderWidth;

  HcAvatarTheme(
      {double? size,
      double? radius,
      Color? textColor,
      TextStyle? textStyle,
      int? changeDuration,
      Color? borderColor,
      Color? backgroundColor,
      double? borderWidth})
      : _size = size,
        _radius = radius,
        _textColor = textColor,
        _changeDuration = changeDuration,
        _textStyle = textStyle,
        _borderColor = borderColor,
        _borderWidth = borderWidth,
        _backgroundColor = backgroundColor;

  @override
  void initTheme({HcCommonTheme? tempTheme}) {
    super.initTheme(tempTheme: tempTheme);
    HcAvatarTheme avatarTheme = HcCustomerConfig().allTheme.avatarTheme;
    _size ??= commonTheme.avatarSizeMd;
    _radius ??= commonTheme.radiusCircle;
    _changeDuration ??= commonTheme.durationBase;
    _textColor ??= avatarTheme.textColor;
    _textStyle ??= avatarTheme.textStyle
        .merge(TextStyle(color: _textColor).merge(_textStyle));
    _backgroundColor ??= avatarTheme.backgroundColor;
    _borderWidth ??= avatarTheme.borderWidth;
    _borderColor ??= avatarTheme.borderColor;
  }

  @override
  HcAvatarTheme merge(HcAvatarTheme? value) {
    if (value == null) return this;
    return copyWith(
      size: value._size,
      radius: value._radius,
      textColor: value._textColor,
      textStyle: textStyle
          .merge(TextStyle(color: value._textColor).merge(value._textStyle)),
      backgroundColor: value._backgroundColor,
      borderColor: value._borderColor,
      borderWidth: value._borderWidth,
      changeDuration: value._changeDuration,
    );
  }

  HcAvatarTheme copyWith({
    double? size,
    double? radius,
    Color? textColor,
    TextStyle? textStyle,
    Gradient? gradient,
    Color? backgroundColor,
    Color? borderColor,
    double? borderWidth,
    List<BoxShadow>? shadow,
    int? changeDuration,
  }) {
    return HcAvatarTheme(
        size: size ?? _size,
        radius: radius ?? _size,
        textColor: textColor ?? _textColor,
        textStyle: textStyle ?? _textStyle,
        backgroundColor: backgroundColor ?? _backgroundColor,
        borderWidth: borderWidth ?? _borderWidth,
        borderColor: borderColor ?? _borderColor,
        changeDuration: changeDuration ?? _changeDuration);
  }

  double get radius =>
      _radius ?? HcDefaultThemeConfig.defaultAvatarTheme.radius;

  double get size => _size ?? HcDefaultThemeConfig.defaultAvatarTheme.size;

  TextStyle get textStyle =>
      _textStyle ?? HcDefaultThemeConfig.defaultAvatarTheme.textStyle;

  Color get textColor =>
      _textColor ?? HcDefaultThemeConfig.defaultAvatarTheme.textColor;

  Color get borderColor =>
      _borderColor ?? HcDefaultThemeConfig.defaultAvatarTheme.borderColor;

  int get changeDuration =>
      _changeDuration ?? HcDefaultThemeConfig.defaultAvatarTheme.changeDuration;

  Color get backgroundColor =>
      _backgroundColor ??
      HcDefaultThemeConfig.defaultAvatarTheme.backgroundColor;

  double get borderWidth =>
      _borderWidth ?? HcDefaultThemeConfig.defaultAvatarTheme.borderWidth;
}
